/**************************************************************************************
*
*	Copyright (C) 2010 - 2012 Brent Andrew O. Chua - See LICENSE.txt for more info.
*		
*	Filename	-	Frustum.h
*
*	Description -	A frustum! 
*
*	Comments	-
*
*	Modification History:
*			Name			   Date					Description
*			MrCodeSushi	-	06/25/2013	-	Creation of this file
**************************************************************************************/
#ifndef _PSX_FRUSTUM_H_
#define _PSX_FRUSTUM_H_

#include "PulseSTD.h"
#include "Plane.h"
#include "Vector3.h"
#include "Matrix4x4.h"

namespace Pulse
{
	PSX_EnumBegin( EFrustumSide )
		LEFT,
		TOP,
		RIGHT,
		BOTTOM,
		_NEAR,
		_FAR,
	PSX_EnumEnd()

	PSX_EnumBegin( EFrustumPoints )
		RIGHT_BOTTOM_FAR,
		RIGHT_BOTTOM_NEAR,
		RIGHT_TOP_FAR,
		RIGHT_TOP_NEAR,
        LEFT_BOTTOM_FAR, 
        LEFT_BOTTOM_NEAR,
        LEFT_TOP_FAR,
        LEFT_TOP_NEAR,
	PSX_EnumEnd()

	class Frustum
	{
	public:

		Frustum( void );

		Frustum( const Matrix4x4 &view, const Matrix4x4 &projection );

		Frustum( const Matrix4x4 &view, FLOAT fov, FLOAT aspect, FLOAT _near, FLOAT _far );

		// NOTE: Calculate the 6 frustum planes based on the specified matrices.
		void Update( const Matrix4x4 &view, const Matrix4x4 &projection );
		
		// NOTE: Calculate the 6 frustum planes based on the specified values.
		void Update( const Matrix4x4 &view, FLOAT fov, FLOAT aspect, FLOAT _near, FLOAT _far );
		
		// NOTE: Recompute the 8 corner points of the frustum based on the supplied planes.
		void RecomputePoints( void );

		BOOL TestPoint( const Vector3 &pos ) const;

		BOOL TestSphere( const Vector3 &pos, const FLOAT radius ) const;

	public:

		Plane m_planes[EFrustumSide::EnumCount];
		Vector3 m_points[EFrustumPoints::EnumCount];
		
	};

	PSX_INLINE BOOL Frustum::TestPoint( const Vector3 &pos ) const
	{
		return TestSphere( pos, 0.0f );
	}

}

#endif /* _PSX_FRUSTUM_H_ */